<?php
// 版本数据接口：返回所有版本（按日期倒序）
header("Content-Type: application/json; charset=utf-8");

// 数据库配置（使用你的信息）
$dbConfig = [
    'host' => 'localhost',
    'user' => 'itops_help1_center',
    'pass' => 'itops_help1_center',
    'name' => 'itops_help1_center'
];

// 连接数据库
$conn = mysqli_connect(
    $dbConfig['host'],
    $dbConfig['user'],
    $dbConfig['pass'],
    $dbConfig['name']
);

if (!$conn) {
    echo json_encode(["status" => "error", "message" => "数据库连接失败：" . mysqli_connect_error()]);
    exit;
}

// 查询所有版本（按发布日期倒序，最新的在前）
$sql = "SELECT version_name, version_code, release_date, update_type, changes 
        FROM versions 
        ORDER BY release_date DESC";
$result = mysqli_query($conn, $sql);

$versions = [];
if ($result && mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        $versions[] = $row;
    }
}

// 返回数据
echo json_encode([
    "status" => "success",
    "data" => $versions
]);
exit;